package com.bdqn.Demo.controller;

import com.bdqn.Demo.pojo.SysUser;
import com.bdqn.Demo.utils.Constants;
import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class SysInterceptor extends HandlerInterceptorAdapter {
    private static final Logger logger=Logger.getLogger(SysInterceptor.class);
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,Object handler)throws Exception{
        logger.debug("进入自定义拦截器==>SysInterceptor");
        HttpSession session=request.getSession();

        SysUser sysUser=(SysUser)session.getAttribute(Constants.USER_SESSION);
        if(null==sysUser){
            response.sendRedirect(request.getContextPath()+"/401.jsp");
            return false;
        }
        return true;
    }
}
